// WordleGame.cpp
#include "WordleGame.h"

#include <QStringList>
#include <QRandomGenerator>

WordleGame::WordleGame(QObject *parent) : QObject(parent) {
    // Initialize the Wordle game
    QStringList wordList = {"apple", "banana", "orange", "grape", "pear", "peach", "melon", "kiwi", "plum", "cherry"};
    targetWord = wordList.at(QRandomGenerator::global()->bounded(wordList.size()));
    maxAttempts = 6;
    remainingAttempts = maxAttempts;
}

void WordleGame::makeGuess(const QString& guess) {
    currentGuess = guess.toLower(); // Convert guess to lowercase for case-insensitive comparison
    // Check if guess matches the target word
    if (currentGuess == targetWord) {
        // Win condition
        remainingAttempts = 0;
    } else {
        remainingAttempts--;
    }
}

QString WordleGame::getGameStatus() const {
    // Generate game status string
    QString status = "Attempts left: " + QString::number(remainingAttempts) + "\n";
    if (remainingAttempts == 0) {
        status += "Game Over. The word was: " + targetWord;
    } else {
        status += "Current Guess: " + currentGuess;
    }
    return status;
}

